package com.davy.gridpoint;

import android.Manifest;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.Settings;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.davy.gridpoint.activity.GridActivity;
import com.davy.gridpoint.activity.GridMainActivity;
import com.davy.gridpoint.activity.HomeActivity;
import com.davy.gridpoint.activity.MainActivity;
import com.davy.gridpoint.activity.PointListActivity;
import com.davy.gridpoint.utils.SPUtils;
import com.davy.gridpoint.utils.StringUtils;
import com.davy.gridpoint.utils.ToastUtil;

import java.util.Timer;
import java.util.TimerTask;

public class StartActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setBackgroundDrawableResource(android.R.color.white); // 使用你的应用的主题颜色
        setContentView(R.layout.activity_start);
        statusbar4();

        // 检查权限
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, Manifest.permission.MANAGE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.MANAGE_EXTERNAL_STORAGE}, 1001);
        }

        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                /**
                 *要执行的操作
                 */
                String strSelect = SPUtils.get(mContext, "strSelect", "") + "";
                if (StringUtils.isEmpty(strSelect)) {
                    startActivity(new Intent(mContext, HomeActivity.class));
                } else {
                    startActivity(new Intent(mContext, MainActivity.class));
                }
                finish();
            }
        };
        Timer timer = new Timer();
        timer.schedule(task, 2500);
    }
}
